﻿-- ============================================================
-- MembershipPower Reference Data Synchronization Script
-- ============================================================

CREATE TABLE #MembershipPower
(
	[Id] [int] NOT NULL,
	[Name] [nchar](50) COLLATE Latin1_General_CI_AS_KS_WS  NOT NULL,
	[Desc] [nvarchar](100) COLLATE Latin1_General_CI_AS_KS_WS  NULL
);

INSERT #MembershipPower ([Id], [Name], [Desc]) VALUES (1001, N'User', N'User management')
INSERT #MembershipPower ([Id], [Name], [Desc]) VALUES (1002, N'Role', N'Role management')


MERGE [dbo].[MembershipPower] AS Target
	USING #MembershipPower AS Source
	ON (Target.[Id] = Source.[Id])
		WHEN MATCHED THEN 
			UPDATE SET Target.[Name] = Source.[Name]
					 , Target.[Desc] = Source.[Desc]
		WHEN NOT MATCHED BY TARGET THEN
			INSERT ([Id], [Name], [Desc])
			VALUES (Source.[Id], Source.[Name], Source.[Desc])
		WHEN NOT MATCHED BY SOURCE THEN 
			DELETE;

DROP TABLE #MembershipPower;


GO
